<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta charset="utf-8">
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<script type="text/javascript" src="../../layui/layui.all.js"></script>
		<title>注册</title>
		<!-- <script type='text/javascript' src='jquery-1.7.2.js'></script> -->

		<script type='text/javascript'>
			function checkEmail(str) {
				var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
				if(!re.test(str) && str == "") {
					alert("邮箱账号格式错误");
					return false;
				}
			}

			var code; //在全局定义验证码   
			function createCode() {
				code = "";
				var codeLength = 4; //验证码的长度   
				var checkCode = document.getElementById("code");
				var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
					'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //随机数   
				for(var i = 0; i < codeLength; i++) { //循环操作   
					var index = Math.floor(Math.random() * 36); //取得随机数的索引（0~35）   
					code += random[index]; //根据索引取得随机数加到code上   
				}
				checkCode.value = code; //把code值赋给验证码   
			}
			//校验验证码   
			$(function() {
				$("#l").click(function() {
						var email =$("#email").val() ; 
						console.log(email)
						var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
						if(reg.test(email)){
							
						}else{ 
							alert("邮箱格式不正确"); 
						}
					var password = document.getElementById("password").value;
					var inputCode = document.getElementById("input").value.toUpperCase(); //取得输入的验证码并转化为大写         
					var name = $("#name").val();
					var email = $("#email").val();
					var passwordTwo = $("#password1").val();
					var userId = 12345;
					if($("#name").val() == "") {
						alert("用户名不能为空");
						return false;
					} else if(password.length < 6) {
						alert("密码至少为6位！");
						$("#password").val("");
						return false;
					} else if($("#password1").val() != password) {
						$("#password1").val("");
						$("#password").val("");
						alert("密码输入不一致");
						return false;
					} else if(email != "") {
						checkEmail(email);
					} else if(inputCode.length <= 0) { //若输入的验证码长度为0
						alert("请输入验证码！"); //则弹出请输入验证码   
						return false;
					} else if(inputCode != code) { //若输入的验证码与产生的验证码不一致时   
						alert("验证码输入错误！@_@"); //则弹出验证码输入错误   
						createCode(); //刷新验证码   
						document.getElementById("input").value = ""; //清空文本框   
						return false;
					} //输入正确时 
					$.ajax({
						type: "Get",
						url: "/server/admin/addUser?userEmail=" + email + "&userPassword=" + password + "&userName=" + name,
						async: true,
						data: {

						},
						success: function(data) {
							if(data.code == 0) {
								layer.msg("注册成功");
								window.setTimeout("location.href = 'UserLogin.html'", 2000);
							}else{
								$("#password1").val("");
								$("#password").val("");								
								layer.msg(data.data);
							}

						}
					})

				})
			})
		</script>
		<style type='text/css'>
			#code {
				font-family: Arial, 宋体;
				font-style: italic;
				color: blue;
				size: 12px;
				border: 0;
				padding: 2px 3px;
				letter-spacing: 8px;
				font-weight: bolder;
			}
		</style>
	</head>

	<body onload='createCode()' background="" style="background-size:100%; background-repeat: no-repeat; margin: 0px; padding: 0px;">
		<img src="../../img/HaiBaLogo.png" style="width: 100px; height: 100%; display:block; padding: 1px; margin: 1px;">
		<table border=0 id="max">
			<tr>
				<th width=700 height=400></th>
				<th>
					<form action="dd.html" method="get">
						<table border=0 height=400>
							<tr>
								<th height=65>用 户 名</th>
								<th>
									<input type="text" style="height:40px" placeholder="请输入用户名" size=40 name="username" id="name">
								</th>
							</tr>
							<tr>
								<th height=65>密 码</th>
								<th>
									<input type="password" style="height:40px" placeholder="密码长度为6~18字符" size=40 id="password">
								</th>
							</tr>
							<tr>
								<th height=65>确认密码</th>
								<th>
									<input type="password" style="height:40px" placeholder="请重新输入密码" size=40 id="password1">
								</th>
							</tr>
							<tr>
								<th height=65>邮箱</th>
								<th>
									<input type="text" style="height:40px" placeholder="邮箱地址" size=40 name="username" id="email">
								</th>
							</tr>
							<tr>
								<th>验 证 码</th>
								<th>
									<input type="text" id="input" style="height:40px;width:220px" />
									<input type="button" id="code" onclick="createCode()" style="height:40px;width:80px" title='点击更换验证码' />
								</th>
							</tr>

							<tr>
							</tr>
							<tr>
								<th colspan=2 height=65><input type='button' style="background-color:red;height:55px;width:160px;font-size:25px;color:white;border:none" value='注册' id='l'></th>
							</tr>
						</table>
					</form>
				</th>
			</tr>
		</table>
		<table>
			<tr>
			</tr>
		</table>
	</body>

</html>